package library.algorithm;

import java.util.List;

public class BinaryFind<Type> implements ArrayFind<Type> {

	@Override
	public int find(List<Type> in, Type t) {
     int lp, rp, mp;
     Comparable<Type> ltype;
     
     for(lp = 0, rp = in.size() - 1; lp <= rp;) {
       mp = (lp + rp) / 2;
       ltype = (Comparable<Type>)in.get(mp);
       if(ltype.compareTo(t) == 0)
        return mp;
       else if(ltype.compareTo(t) > 0)
        rp = mp -1;
       else
        lp = mp +1;
     }
     return -1;
	}
}

